package light.mvc.controller.sys;

import javax.servlet.http.HttpServletRequest;

import light.mvc.controller.base.BaseController;
import light.mvc.pageModel.base.Grid;
import light.mvc.pageModel.base.Json;
import light.mvc.pageModel.base.PageFilter;
import light.mvc.pageModel.sys.SendLogVO;
import light.mvc.service.sys.SendLogServiceI;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/sendLog")
public class SendLogController extends BaseController {

	@Autowired
	private SendLogServiceI sendLogService;

	@RequestMapping("/manager")
	public String manager() {
		return "/sys/sendLog";
	}

	@RequestMapping("/dataGrid")
	@ResponseBody
	public Grid dataGrid(SendLogVO sendLog, PageFilter ph) {
		Grid grid = new Grid();
		grid.setRows(sendLogService.dataGrid(sendLog, ph));
		grid.setTotal(sendLogService.count(sendLog, ph));
		return grid;
	}

	@RequestMapping("/viewPage")
	public String viewPage(HttpServletRequest request, Long id) {
		SendLogVO r = sendLogService.get(id);
		request.setAttribute("sendLog", r);
		return "/sys/sendLogView";
	}

	@RequestMapping("/addPage")
	public String addPage() {
		return "/sys/sendLogAdd";
	}

	@RequestMapping("/add")
	@ResponseBody
	public Json add(SendLogVO sendLog) {
		Json j = new Json();
		try {
			sendLogService.add(sendLog);
			j.setSuccess(true);
			j.setMsg("添加成功！");
		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/delete")
	@ResponseBody
	public Json delete(Long id) {
		Json j = new Json();
		try {
			sendLogService.delete(id);
			j.setMsg("删除成功！");
			j.setSuccess(true);
		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/get")
	@ResponseBody
	public SendLogVO get(Long id) {
		return sendLogService.get(id);
	}

	@RequestMapping("/editPage")
	public String editPage(HttpServletRequest request, Long id) {
		SendLogVO r = sendLogService.get(id);
		request.setAttribute("sendLog", r);
		return "/sys/sendLogEdit";
	}

	@RequestMapping("/edit")
	@ResponseBody
	public Json edit(SendLogVO sendLog) {
		Json j = new Json();
		try {
			sendLogService.edit(sendLog);
			j.setSuccess(true);
			j.setMsg("编辑成功！");
		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		return j;
	}
}